const rm = require('rimraf')
const path = require('path')
const __root__ = process.cwd()
const {
	webpack
} = require('./client-web')
const {
	port,
} = require('./server-app/config/sysConf')

module.exports = function(grunt) {

	require('./client-web');
	require('load-grunt-tasks')(grunt);

	require('time-grunt')(grunt);

	grunt.initConfig({
		webpack: {
			dev,
			pro,
		},
		nodemon: {
			dev: {
				options: {
					file: 'server-app.js',
					args: [],
					ignoredFiles: ['README.md', 'node_modules/**', '.DS_Store'],
					watchedExtensions: ['js'],
					watchedFolders: ['./'],
					debug: true,
					delayTime: 1,
					env: {
						PORT: port,
					},
					cwd: __root__,
				}
			}
		},
		concurrent: {
			dev: {
				tasks: ['watch:dev', 'nodemon:dev'],
				options: {
					logConcurrentOutput: true,
				}
			},
		},
		watch: {
			dev: {
				files: ['client-apis-man/src/**'],
				tasks: ['webpack:dev'],
				options: {
					spawn: false,
					reload: true,
				},
			},
		},
	});

	grunt.loadNpmTasks('grunt-contrib-watch');
	grunt.loadNpmTasks('grunt-nodemon');
	grunt.loadNpmTasks('grunt-concurrent')
	grunt.loadNpmTasks('grunt-webpack')

	grunt.registerTask('s', ['nodemon:dev'])
	grunt.registerTask('dev', ['webpack:dev']);

}